package com.lagou.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/email")
public class EmailController  {

    @Value("${spring.mail.username}")
    private String from;

    @Autowired
    private JavaMailSender mailSender;

    @PostMapping("/{email}/{code}")
    public Boolean sendEmail(@PathVariable String email,@PathVariable String code) {

        try {

            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(from);
            message.setTo(email);
            message.setSubject("验证码");
            message.setText(code);
            mailSender.send(message);

        } catch (Exception e) {

            return false;
        }

        return true;
    }
}
